package com.trimer.rpc.controller;

import com.trimer.rpc.demo.service.HelloService;
import com.trimer.rpc.proxy.RpcInvoker;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
@RequestMapping("/client")
public class HelloController {

    @Autowired
    private RpcInvoker rpcInvoker;

    @RequestMapping(value = "/hello/greeting", method = RequestMethod.GET)
    @ResponseBody
    public String greeting() {
        HelloService helloService = rpcInvoker.createBean(HelloService.class, null);
        String result = helloService.greeting();
        return result;
    }

    @RequestMapping(value = "/hello", method = RequestMethod.GET)
    @ResponseBody
    public String greeting1() {
        return "hello";
    }

    @RequestMapping(value = "/hello/helloworld/{name}", method = RequestMethod.GET)
    @ResponseBody
    public String HelloWorld(@PathVariable("name") String name) {
        HelloService helloService = rpcInvoker.createBean(HelloService.class, null);
        String result = helloService.HelloWorld(name);
        return result;
    }
}